package per.turtle.system.feign.fallback;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import per.turtle.common.core.web.entity.CommonResult;
import per.turtle.common.core.web.page.TableDataInfo;
import per.turtle.system.dto.LoginUser;
import per.turtle.system.entity.SysUser;
import per.turtle.system.feign.RemoteUserService;

/**
 * 用户服务降级处理
 *
 * @author turtle
 */
@Slf4j
@Component
public class RemoteUserFallbackImpl implements RemoteUserService {

    @Setter
    private Throwable cause;

    @Override
    public CommonResult<LoginUser> getUserInfo(String username) {
        log.error("用户服务调用失败:{}", cause.getMessage());
        return CommonResult.error("获取用户 <" + username + "> 失败:" + cause.getMessage());
    }

    @Override
    public TableDataInfo<SysUser> selectUserList(SysUser user) {
        log.error("用户服务调用失败:{}", cause.getMessage());
        return TableDataInfo.error();
    }

    @Override
    public CommonResult<LoginUser> selectUserById(String userId) {
        log.error("用户服务调用失败:{}", cause.getMessage());
        return CommonResult.error("获取用户 <" + userId + "> 失败:" + cause.getMessage());
    }

}
